package middleware

import (
	"github.com/gin-gonic/gin"
	"gopkg.in/natefinch/lumberjack.v2"
	"poem-server/comm/response"
	"poem-server/initialize/config"
)

// recover 程序出现异常也要把result返回
func RecoveryHandler() gin.HandlerFunc {
	return gin.RecoveryWithWriter(
		&lumberjack.Logger{
			Filename:   config.Config.Log.RootDir + "/" + config.Config.Log.Filename,
			MaxSize:    config.Config.Log.MaxSize,
			MaxBackups: config.Config.Log.MaxBackups,
			MaxAge:     config.Config.Log.MaxAge,
			Compress:   config.Config.Log.Compress,
		},
		response.ServerError)
}
